/*
 * Copyright (c) 2023, 2023,yzc.cn All rights reserved.
 *
 */
package cn.yzc;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>Project: RabbitMQ - FanoutConfig</p>
 * <p>Powered by yzc On 2023-12-23 14:20:47</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */

/**
 * 发布订阅配置类
 */
@Configuration
public class FanoutConfig {
    /**
     * 向容器中注入 队列一
     * @return name为queueOne的队列
     */
    @Bean
    public Queue queueOne(){
        return new Queue("queueOne");
    }

    /**
     * 向容器注入队列二
     */
    @Bean
    public Queue queueTwo(){
        return QueueBuilder.durable("queueTwo")
                .build();
    }

    /**
     * 声明交换器
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("pubsub-ex");
    }

    /**
     * 绑定队列一与交换器
     * @param queueOne  队列一在容器中的bean中的名称
     * @param fanoutExchange 交换器
     * @return
     */
    @Bean
    public Binding bindingOne(Queue queueOne,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queueOne).to(fanoutExchange);
    }
    /**
     * 绑定队列二与交换器
     * @param queueTwo  队列二在容器中的bean中的名称
     * @param fanoutExchange 交换器
     * @return
     */
    @Bean
    public Binding bindingTwo(Queue queueTwo,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queueTwo).to(fanoutExchange);
    }
}
